home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / sys / mac / macsnd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  2.3 KB  |  105 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)macsnd.c    3.1    92/11/28    */
  2. /*     Copyright (c) 1992 by Jon Watte */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. /*
  6.  * This file contains music playing code.
  7.  *
  8.  * If we were REALLY determinated, we would make the sound play
  9.  * asynchronously, but I'll save that one for a rainy day...
  10.  *
  11.  * This may break A/UX, since it defines MAC but we need to
  12.  * check that the toolbox is booted. I'll defer that one too.
  13.  *
  14.  * - h+ 921128
  15.  */
  16.  
  17. #include "hack.h"
  18. #include <Sound.h>
  19. #include <Resources.h>
  20.  
  21. #define SND_BUFFER(s) (&(*s)[20])
  22. #define SND_LEN(s) (GetHandleSize(s)-42)
  23.  
  24. void mac_speaker ( struct obj * instr , char * melody ) ;
  25.  
  26. void
  27. mac_speaker ( struct obj * instr , char * melody )
  28. {
  29.     SndChannelPtr theChannel = (SndChannelPtr) NULL ;
  30.     SndCommand theCmd ;
  31.     Handle theSound ;
  32.     unsigned char theName [ 32 ] ;
  33.     char * n = ( char * ) & theName [ 1 ] ;
  34.     int typ = instr -> otyp ;
  35.     const char * actualn = OBJ_NAME ( objects [ typ ] ) ;
  36.  
  37.     /*
  38.      * First: are we in the library ?
  39.      *
  40.      */
  41.     if ( flags . silent ) {
  42.  
  43.         return ;
  44.     }
  45.  
  46.     /*
  47.      * Is this a known instrument ?
  48.      *
  49.      */
  50.     strcpy ( n , actualn ) ;
  51.     theName [ 0 ] = strlen ( n ) ;
  52.     theSound = GetNamedResource ( 'snd ' , theName ) ;
  53.     if ( ! theSound ) {
  54.  
  55.         return ;
  56.     }
  57.     HLock ( theSound ) ;
  58.  
  59.     /*
  60.      * Set up the synth
  61.      *
  62.      */
  63.     if ( itworked ( SndNewChannel ( & theChannel , sampledSynth , initMono +
  64.         initNoInterp , ( void * ) NULL ) ) ) {
  65.  
  66.         char midi_note [ ] = { 57 , 59 , 60 , 62 , 64 , 65 , 67 } ;
  67.  
  68.         short err ;
  69.         short snd_len = SND_LEN ( theSound ) / 18 ;
  70.  
  71.         theCmd . cmd = soundCmd ;
  72.         theCmd . param1 = 0 ;
  73.         theCmd . param2 = (long) SND_BUFFER ( theSound ) ;
  74.         err = SndDoCommand ( theChannel , & theCmd , false ) ;
  75.  
  76.     /*
  77.      * We rack 'em up all in a row
  78.      * The mac will play them correctly and then end, since
  79.      * we do a sync close below.
  80.      *
  81.      */
  82.         while ( * melody && ! err ) {
  83.  
  84.             while ( * melody > 'G' ) {
  85.  
  86.                 * melody -= 8 ;
  87.             }
  88.             while ( * melody < 'A' ) {
  89.  
  90.                 * melody += 8 ;
  91.             }
  92.             theCmd . cmd = freqDurationCmd ;
  93.             theCmd . param1 = snd_len ;
  94.             theCmd . param2 = midi_note [ * melody - 'A' ] ;
  95.             err = SndDoCommand ( theChannel , & theCmd , false ) ;
  96.             melody ++ ;
  97.         }
  98.         SndDisposeChannel ( theChannel , false ) ;
  99.             /* Sync wait for completion */
  100.         ReleaseResource ( theSound ) ;
  101.  
  102.         mustwork ( err ) ;
  103.     }
  104. }
  105.